/*
 * Copyright 2009 Vladimir Ritz Bossicard
 *
 * This file is part of OraDoc.
 *
 * OraDoc is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * Version     : $Revision: 23 $
 * Last edit   : $Date: 2009-05-29 11:58:29 +0000 (Fri, 29 May 2009) $
 * Last editor : $Author: vbossica $
 */
package org.oradoc.utils.freemarker;

import java.io.File;
import java.io.FileWriter;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;

/**
 * FIXME replace with FreemarkerSupport
 * 
 * @author Vladimir Ritz Bossicard
 */
public class HtmlOutputTemplate {

    private Map<String, Object> model;
    private Configuration cfg;
    private String template;

    public HtmlOutputTemplate(final Map<String, Object> model,
            final Configuration cfg, final String template) {
        this.model = model;
        this.cfg = cfg;
        this.template = template;
    }

    public void process(final File outDir, final String filename) throws Exception {
        Template template = this.cfg.getTemplate(this.template);

        FileWriter writer = new FileWriter(new File(outDir, filename));
        try {
            template.process(this.model, writer);
        } finally {
            writer.flush();
            writer.close();
        }
    }

}
